package com.oocl.query.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.catalina.startup.SetAllPropertiesRule;

import com.oocl.query.pojo.Infomation;
import com.oocl.query.util.DBUtil;

public class InfomationDaoImpl implements InfomationDao {

	@Override
	public List<Infomation> findByQuery(String param) {
		List<Infomation> list = new ArrayList<Infomation>();
		String sql = "select * from areas  where area like ? and rownum<=20";
		Connection con = null;
		PreparedStatement pst = null;
		ResultSet rs = null;
		try {
			con = DBUtil.createConnection();
			pst = con.prepareStatement(sql);
			pst.setString(1, "%"+param+"%");
			rs = pst.executeQuery();
			System.out.println(rs);
			while (rs.next()) {
				Infomation info = new Infomation();
				info.setId(rs.getInt("id"));
				info.setAreaid(rs.getString("areaid"));
				info.setArea(rs.getString("area"));
				info.setCityid(rs.getString("cityid"));
				list.add(info);
			}
			return list;
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBUtil.close(con, pst, rs);
		}
		return list;
	}

}
